#include "vtor_game.h"
#include "vtor_elec_module.h"

#ifdef __USER_DEMO_PROJECT__

// 屏幕缓存
extern uint8_t OLED_GRAM[8][128];

// map地图数据本体
uint8_t snake1MapData[8][16] = {0};

// 方便扩充的地图数组
VtorMap VtorMap_Array[1] = {
	(int8_t*)snake1MapData, 16, 8,
};

// 外界使用的地图实例指针
VtorMap* snake1Map = &VtorMap_Array[0];



uint8_t lifeGame1CalcMapData[8 / 8][128] = {0};
uint8_t lifeGame1ShowMapData[8 / 8][128] = {0};
// 方便扩充的地图数组
VtorBitMap VtorBitMap_Array[2] = {
	(int8_t*)lifeGame1CalcMapData, 128, 8,
	(int8_t*)lifeGame1ShowMapData, 128, 8,
};

// 外界使用的地图实例指针
VtorBitMap* lifeGame1CalcMap = &VtorBitMap_Array[0];
VtorBitMap* lifeGame1ShowMap = &VtorBitMap_Array[1];

void VtorMap_Draw(VtorMap* map)
{
	// 针对示例的刷新方法
	if(map == snake1Map)
	{
		for(int16_t h = 0; h < map->height; h++)
		{
			for(int16_t w = 0; w < map->width; w++)
			{
				int8_t ele = VtorMap_GetElement(map, w, h);
				if(ele == VtorSnake_SNAKE)
				{
					ele = 0xff;
				}
				else if(ele == VtorSnake_FOOD)
				{
					ele = 0xf0;
				}
				if(ele)
				{
					for(int8_t i = 0; i < 8; i++)
					{
						OLED_GRAM[h][w * 8 + i] = ele;
					}
				}
			}
		}
	}
}

void VtorBitMap_Draw(VtorBitMap* map)
{
	// 针对实例的刷新方法
	if(map == lifeGame1ShowMap || lifeGame1CalcMap)
	{
		for(int16_t h = 0; h < map->height / 8; h++)
		{
			for(int16_t w = 0; w < map->width; w++)
			{
				int8_t ele = VtorMap_GetElement((VtorMap*)map, w, h);
				OLED_GRAM[h][w] = ele;
				//int8_t ele = VtorBitMap_GetElement(map, w, h);
				//OLED_DrawPoint(w, h, ele);
				
			}
		}
	}
}

#endif

